<!DOCTYPE html>
<html>
<head lang="en">
    <title>搜索结果:</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategy.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>

</head>
<script>
    $(function () {
        var params = getParams();
        var keyword = decodeURIComponent(params.keyword);
        $(".search p").html("您搜索的关键字是:" + keyword);

        var type = 1;

        //查询攻略条数
        $.get('/strategies/'+keyword+"/countNum",function (data) {
            $(".strategy").html("攻略("+data+")")
        })
        $("#1").removeAttr("style")
        //发送请求获取数据
        $.get('/strategies/' + keyword + '/search', function (data) {
            console.log(data.total);
            if (data.total != 0) {
                //渲染数据
                $("#pills-strategy").renderValues(data, {
                    getHref: getHref
                })
            } else {
                //添加禁止点击样式
                $("#1").attr("style","pointer-events: none")

                $(".travel").trigger("click");
            }
        })


        //查询攻略条数
        $.get('/travels/'+keyword+"/countNum",function (data) {

            $(".travel").html("游记("+data+")")
        })

        $.get('/dailyPaper/'+keyword+"/countNum",function (data) {
            $(".newsPage").html("日报("+data+")")
        })
        //给按钮绑定点击事件
        $(".clickTab").click(function () {
            //获取按钮上的值
            type = $(this).data("type")
            console.log(type);
            if (type == 2) { //游记
                query();
            }else if(type==3){//日报
                query1();
            }

            //当前页
            var currentPage = 1;
            //总页数
            var pages = 1;
            //是否查询的标记
            var loading = false;
            //用户存储游记的数组容器
            var travelData=[];
            //用户存储游记的数组容器
            var dailyPaperData=[];
            //查询方法
            function query() {
                //如果正在查询就不继续查了,退出
                if (loading) {
                    return;
                }
                //设置为查询状态
                loading = true;
                console.log("进入方法");
                $("#2").removeAttr("style")
                //全部攻略
                $.get('/travels/' + keyword + '/search', {currentPage: currentPage}, function (data) {
                    console.log(data);
                    if(data.total!=0){
                        //把查询的数据放到容器中
                        $.merge(travelData,data.list);
                        //将容器封装到属性为list的对象中
                        var json = {list:travelData};
                        //渲染数据
                        $("#pills-travel").renderValues(json, {
                            getHref: getHref
                        })
                    }else{
                        console.log("执行方法");
                        /*$(document).dialog({
                            titleText: "温馨提示",
                            content: "找不到与关键字相匹配的游记内容",

                        });*/
                        //添加禁止点击样式
                        $("#2").attr("style","pointer-events: none")
                        $(".newsPage").trigger("click");
                    }

                    //当前页+1
                    currentPage++;
                    //总页数
                    pages = data.pages;
                    //设置为没有在查询  本次查询结束
                    loading = false;
                }, "json");
            }


            //查询方法
            function query1() {
                //如果正在查询就不继续查了,退出
                if (loading) {
                    return;
                }
                //设置为查询状态
                loading = true;
                //console.log("进入方法");
                $("#3").removeAttr("style")
                //全部攻略
                $.get('/dailyPaper/', {currentPage: currentPage,keyword:keyword}, function (data) {
                    console.log(data);
                    if(data.total!=0){
                        //把查询的数据放到容器中
                        $.merge(dailyPaperData,data.list);
                        //将容器封装到属性为list的对象中
                        var json = {list:dailyPaperData};
                        //渲染数据
                        $("#pills-newsPage").renderValues(json, {
                            getHref: getHref
                        })
                    }else{
                        console.log("执行方法");
                        $(document).dialog({
                            titleText: "温馨提示",
                            content: "找不到与关键字相匹配的内容",

                        });
                        //添加禁止点击样式
                        $("#3").attr("style","pointer-events: none")
                    }

                    //当前页+1
                    currentPage++;
                    //总页数
                    pages = data.pages;
                    //设置为没有在查询  本次查询结束
                    loading = false;
                }, "json");
            }


            //滚动页面 触发事件 翻页
            $(window).scroll(function () {
                //判断是否滚动到底部了  窗口的高度+文档滚动的高度 大于等于 文档的高度
                if ($(window).height() + $(document).scrollTop() + 1 >= $(document).height()) {
                    //如果当前页大于总页数就不查询了
                    if (currentPage <= pages) {
                        //查询
                        query();
                    } else {
                        $(document).dialog({
                            type: 'notice',
                            infoText: '亲,已经到底了',
                            autoClose: 1500,
                            position: 'center'  // center: 居中; bottom: 底部
                        });
                    }

                }
            });
        })
    });
</script>
<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <p style="color: white; font-size: 20px"></p>
            </div>
        </div>
    </div>
</div>

<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab" role="tablist">
    <li class="nav-item" style="width: 33%" id="1">
        <a role="button" id="strategy" class="nav-link clickTab active show" data-type="1" data-toggle="pill"
           href="#pills-strategy">
            <span class="strategy"></span>
        </a>
    </li>
    <li class="nav-item" style="width: 33%" id="2">
        <a role="button" id="travel" class="nav-link clickTab" data-type="2" data-toggle="pill"
           href="#pills-travel">
            <span class="travel"></span>
        </a>
    </li>
    <li class="nav-item" style="width: 33%" id="3">
        <a role="button" id="newsPage" class="nav-link clickTab" data-type="3" data-toggle="pill"
           href="#pills-newsPage">
            <span class="newsPage"></span>
        </a>
    </li>

</ul>
<div class="tab-content" id="pills-tabContent">
    <div class="tab-pane fade active show" id="pills-strategy">
        <div render-loop="list">
            <div class="container commend">
                <a data-url="strategyCatalogs.html?id=" render-fun="getHref" render-key="list.id">
                    <p render-html="list.title"></p>
                    <img render-src="list.coverUrl">
                </a>
            </div>
            <hr>
        </div>
    </div>
    <div class="tab-pane fade" id="pills-travel">
        <div render-loop="list">
            <div class="container commend">
                <a data-url="travelContent.html?id=" render-fun="getHref" render-key="list.id">
                    <p render-html="list.title"></p>
                    <img render-src="list.coverUrl">
                </a>
            </div>
            <hr>
        </div>
    </div>
    <div class="tab-pane fade" id="pills-newsPage">
        <div render-loop="list">
            <div class="container commend">
                <a data-url="/dailypaperContent.html?id=" render-fun="getHref" render-key="list.id">
                    <p render-html="list.title"></p>
                    <img render-src="list.coverUrl">
                </a>
            </div>
            <hr>
        </div>
    </div>
</div>
</body>
</html>
